<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport"
          content="width=device-width,height=device-height, initial-scale=1,maximum-scale=1,user-scalable=0">
    <title>招聘信息</title>
    <link rel="stylesheet" href="../tool/jquery-mobile/jquery.mobile-1.4.2.min.css">
    <link rel="stylesheet" href="../css/default.min.css">
    <link rel="stylesheet" href="../css/login.css">
    <link rel="stylesheet" href="../css/resume.css">
    <link rel="stylesheet" href="../tool/swiper/css/swiper.min.css">
    <link rel="stylesheet" href="../css/common.css">

    <script src="../tool/jquery/jquery-1.8.3.min.js"></script>
    <script src="../tool/swiper/js/swiper.min.js"></script>
    <script src="../js/common.js"></script>
    <script src="../js/http.js"></script>
    <style>
        #titleButton {
            height: 30px;
            color: #ffffff;
            background: #ee721a;
            width: 17%;
            font-size: 15px;
            position: absolute;
            left: 10px;
            border: 1px solid #df7100;
        }

        .head-div {
            position: fixed;
            left: 0;
            top: 0;
            width: 100%;
            z-index: 200;
        }

        .content-div {
            height: 500px;
            width: 100%;
            padding-top: 42px;
        }

        body {
            margin: 0;
        }

        .modal {
            width: 70%;
            height: 100%;
            background: #ffffff;
            position: fixed;
            top: 0;
            left: 30%;
            z-index: 1000;
            -webkit-overflow-scrolling: touch;
        }

        .modal .title {
            color: #ffffff;
            background: #ee721a;
            font-size: 17px;
            padding: 10px 20px 10px 20px;
            border-bottom: 1px solid #e0e0e0;
            text-align: right;
        }

        .modal .row {
            color: #808080;
            /*width:100%;*/
            font-size: 17px;
            padding: 10px 20px 10px 20px;
            border-bottom: 1px solid #e0e0e0;
            text-align: center;
        }

        .modal .row:hover {
            color: #ffffff;
            background: #ee721a;
        }
    </style>
</head>
<body>
<div class="head-div">
    <div class="div_header">
        <p class="p_title" style="">岗位详情</p>
        <button id="titleButton" style="padding: 5px 0 5px 0;text-shadow: none;"
                onclick="common.goTo('/html/fairList.html')"
                class=" ui-btn ui-shadow ui-corner-all">返回
        </button>
    </div>
</div>
<div class="content-div">
    <div class="swiper-container" style="float: left;width: 100%;height: 200px;display:none;">
        <div class="swiper-wrapper"></div>
        <div class="swiper-pagination swiper-pagination-white"></div>
    </div>
    <div class="jobcontent" data-role="collapsible" style="float: left;">
        <h4>岗位基本信息</h4>
        <p>
            <span>公司名称：</span><span style="margin-left: 10px;" id="companyName"></span>
        </p>
        <p>
            <span>岗位名称：</span><span style="margin-left: 10px;" id="positionName"></span>
        </p>
        <p>
            <span>薪资范围：</span><span style="margin-left: 10px;" id="salaryScope"><i></i></span>
        </p>
        <p>
            <span>工作地点：</span><span style="margin-left: 10px;" id="workAddress"></span>
        </p>
        <p>
            <span>学历要求：</span><span style="margin-left: 10px;" id="education"></span>
        </p>
        <p>
            <span>面试时间：</span><span style="margin-left: 10px;" id="interviewAt"></span>
        </p>
        <p>
            <span>面试地点：</span><span style="margin-left: 10px;" id="interviewAddress"></span>
        </p>
        <p>
            <span>咨询热线：</span><span style="margin-left: 10px;"><a href="tel:0571-87016962" mce_href="tel:0571-87016962">0571-87016962</a></span>
        </p>
    </div>
    <div class="jobcontent" style="float: left; width: 100%">
        <h4>岗位描述</h4>
        <p id="positionDesc" style="padding: 0 10px 0 10px;"></p>
    </div>
    <div class="jobcontent" style="float: left; width: 100%">
        <h4>公司描述</h4>
        <p id="companyDesc" style="padding: 0 10px 0 10px;"></p>
    </div>
    <div class="jobcontent" style="float: left;margin-bottom: 100px;">
        <p>
            <img id='map' style='width:100%'/>
        </p>
    </div>
</div>
<div class="bottom-button-div">

</div>
<div class="modal" id="message_text" style="display:none">
    <div class="title" onclick="saveMessage()">确定</div>
    <textarea style="width: 100%;height: 100%" id="messageContent">

    </textarea>
</div>
<script>
    var job = {};
    var jobId = common.locationParams()["id"];
    var leaveMessage = "";
    function initSelect(a, b, c, d) {
        $(a).click(function () {
            $("#overlay").css({"display": "block"});
            $(c).css({"display": "block"});
        });
        $(c).find(".title").click(function () {
            $("#overlay").css({"display": "none"});
            $(c).css({"display": "none"});
        });
    };
    function subscribeJob() {
        if (job.login && job.resumeIntegrity < 70) {
            if (confirm("您的简历未完善! 去完善简历?")) {
                window.location.href = common.ctx + "/html/resume.html";
            }
            return;
        }
        http.post({
            url: common.sctx + '/personal/subscribe/job/' + jobId + '.do',
            success: function () {
                alert('预约成功！');
                location.reload();
            },
            error: function (res) {
                alert(res.message);
            }
        })
    }

    function saveMessage() {
        var messageContent = $("#messageContent").val();
        if(messageContent && leaveMessage !== messageContent) {
            http.post({
                url: common.sctx + '/personal/subscribe/job/message/' + jobId + '.do?messageContent='+messageContent,
                success: function () {
                    alert('HR收到留言后第一时间会跟你联系哦！');
                },
                error: function (res) {
                    alert(res.message);
                }
            })
        }
    }

    $(document).ready(function () {
        var loadCompanyPicture = function (imgList) {
            $('.swiper-container').show();
            if (imgList && imgList.length > 0) {
                var imgHtml = [];
                $.each(imgList, function () {
                    var imgUrl = common.jobImgPathRoot + '/' + this;
                    imgHtml.push('<div class="swiper-slide"> <img src="' + imgUrl + '" style="width: 100%;height: 200px;"></div>');
                });
                $('.swiper-wrapper').html(imgHtml.join(""));
            }

            var swiper = new Swiper('.swiper-container', {
                pagination: {
                    el: '.swiper-pagination',
                    clickable: true
                },
                autoplay: {
                    delay: 5000
                }
            });
        };

        var render = function (job) {
            var Not = '暂无';
            var companyName = job.companyName || Not;
            var positionName = job.jobName || Not;
            var salaryScope = job.salaryScope || Not;
            var interviewAt = job.interviewAt || Not;
            var interviewAddress = job.interviewPlace || Not;
            var education = job.education || Not;
            var workAddress = job.jobPlace || Not;
            var positionDesc = job.introduce || Not;
            var companyDesc = job.companyIntroduce || Not;
            leaveMessage = job.leaveMessage;
            $("#companyName").text(companyName);
            $("#positionName").text(positionName);
            $("#salaryScope").text(salaryScope);
            $("#education").text(education);
            $("#positionDesc").text(positionDesc);
            $("#companyDesc").text(companyDesc);
            $("#interviewAt").text(interviewAt);
            $("#messageContent").val(leaveMessage)
            if (job.publish && !job.expire) {
                if (job.login && job.subscribe) {
                    $("#workAddress").text(workAddress);
                    $("#interviewAddress").text(interviewAddress);
                    $(".bottom-button-div").html('<div id="message" style="background-color: #ffffff;width: 30%;float: left"><span>留言</span></div>' +
                        '<div><span style="background-color: #bdb8b5;width: 70%;float: right;">已预约</span></div>');
                    initSelect("#message", "#message_text .row", "#message_text", "#message");
                } else {
                    if (workAddress && workAddress.length > 3) {
                        workAddress = workAddress.substring(0, 3)
                    }
                    if (interviewAddress && interviewAddress.length > 3) {
                        interviewAddress = interviewAddress.substring(0, 3)
                    }
                    $("#workAddress").text(workAddress + "...（点击预约后显示完整地址）");
                    $("#interviewAddress").text(interviewAddress + "...（点击预约后显示完整地址）");
                    $(".bottom-button-div").html('<div onclick="subscribeJob()"><span>我要面试</span></div>');
                }
            } else {
                var message = "";
                if (job.expire) {
                    message = "职位已过期"
                }
                if (!job.publish) {
                    message = "职位已下架"
                }
                $(".bottom-button-div").html('<div><span style="background-color: #bdb8b5">' + message + '</span></div>');
            }

            // 地图
            if (job.lon && job.lat) {
                var map = {labelname: job.labelName || '', lon: job.lon, lat: job.lat};
                var location = map.lon + "," + map.lat;
                var labelLocation = map.lon + "," + (parseFloat(map.lat) + 0.0004);
                var label = map.labelname;
                if (label.length > 15) {
                    label = label.substring(0, 12) + "..."
                }
                $("#map").attr("src", "http://restapi.amap.com/v3/staticmap?location=" +
                    location + "&zoom=16&markers=mid,,:" + location + "&labels=" +
                    label + ",2,0,16,0x000000,0xFFFFFF:" +
                    labelLocation + "&key=ab32e3de61eabff7498af838dd487c3c").attr("alt", map.labelname);
            }
        };
        var jobDetail = function () {
            http.get({
                url: common.sctx + '/job/' + jobId + '/info.do',
                success: function (data) {
                    job = data;
                    render(job);
                    if (job.pictureList && job.pictureList.length > 0) {
                        loadCompanyPicture(job.pictureList);
                    }
                }
            });
        };


        if (jobId) {
            jobDetail();
        }
    });
</script>
</body>
</html>